package com.emergency.examine.controller;

import com.emergency.common.entity.Result;
import com.emergency.common.entity.StatusCode;
import com.emergency.examine.domain.Paper;
import com.emergency.examine.service.PaperService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * Created by lijie on 2019/10/17.
 */
@RestController
@RequestMapping("/paper")
@Api(value = "试卷类", tags = "管理题库，并可以通过题库，自动生成考核试卷")
public class PaperController {
    @Autowired
    private PaperService paperService;

    @ApiOperation(value = "试卷生成或修改接口", notes = "生成或修改试卷")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "note", value = "试卷描述", required = true, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "score", value = "试卷分值", required = true, paramType = "query", dataType = "Double"),
            @ApiImplicitParam(name = "duration", value = "考试时间", required = true, paramType = "query", dataType = "Double")
    })
    @RequestMapping(value = "add", method = RequestMethod.POST)
    public Result add(@RequestBody Paper paper) {
        String id = paperService.add(paper);
        return new Result(true, StatusCode.OK, "操作成功", id);
    }

    @ApiOperation(value = "试卷查询接口", notes = "查询试卷信息")
    @RequestMapping(value = "get/{paperId}", method = RequestMethod.GET)
    public Result get(@PathVariable("paperId") Long paperId) {
        Paper paper = paperService.getInfo(paperId);
        return new Result(true, StatusCode.OK, "操作成功", paper);
    }

    @ApiOperation(value = "试卷删除接口", notes = "试卷删除")
    @RequestMapping(value = "del/{paperId}", method = RequestMethod.POST)
    public Result del(@PathVariable("paperId") Long paperId) {
        paperService.del(paperId);
        return new Result(true, StatusCode.OK, "操作成功");
    }

    @ApiOperation(value = "试卷列表获取接口", notes = "试卷列表")
    @RequestMapping(value = "list/{page}/{size}", method = RequestMethod.POST)
    public Result list(@RequestBody Map searchMap, @PathVariable int page, @PathVariable int size) {
        Page<Paper> pageList = paperService.findList(searchMap, page, size);
        return new Result(true, StatusCode.OK, "操作成功", pageList);
    }
//    @ApiOperation(value = "试题修改接口" ,  notes="试题修改")
//    @RequestMapping(value = "question/update",method = RequestMethod.POST)
//    public Result update(){
//        return new Result(true, StatusCode.OK,  "操作成功", "");
//    }

//    @ApiOperation(value = "试卷生成接口" ,  notes="按照考核类型自动生成试卷")
//    @ApiImplicitParams({
//            @ApiImplicitParam(name = "type", value = "考核类型", required = true, paramType = "query", dataType = "String")
//    })
//    @RequestMapping(value = "generate",method = RequestMethod.POST)
//    public Result generate(@RequestParam(value = "type",required = true) int type){
//        return new Result(true, StatusCode.OK,  "推演成功", "");
//    }
}
